const router = require('express').Router();
const connection = require('../database/mysql')
const path = require('path')
const sql = require('../routehandles/mysqlhandle')

router.post('/updateNickname',async function(req,res)
{
    var params = req.body
    var reg= /^[\u4E00-\u9FA5A-Za-z0-9_]{3,10}$/
    var a = await sql.sUAPTable(params.username)[0]
    console.log(a)
    if(params.nickname == '' || params.nickname == null)
    {
        console.log('昵称为空')
        return res.json({msg:'昵称不能为空',result:false})
    }else if(!params.nickname.match(reg))
    {
        console.log(params.nickname)
        return res.json({msg:'昵称不合法！',result:false})//后期有时间这里再细化
    }else
    {
        console.log('已修改')
        await sql.uUAPTable('nickname',params.nickname,params.username)
        await sql.uPublishTable('nickname',params.nickname,params.username)
        return res.json({msg:'昵称已更新完成',result:true})
    }
})
module.exports = router